/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ec.dmz.sig.ejb.dao;

import ec.dmz.sig.ejb.generico.Generico;
import ec.dmz.sig.ejb.model.Catalogo;
import java.util.List;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.Query;

/**
 *
 * @author Estiwar
 */
@LocalBean
@Stateless
public class CatalogoDao extends Generico<Catalogo>{
      public CatalogoDao() {
        super(Catalogo.class);
    }
     
    
    public List<Catalogo> obtenerCatalogoPadres() throws Exception{
        String jpaQl = "SELECT c FROM Catalogo c"
                + " WHERE c.parentCatCodigo IS NULL";
        Query query = getEntityManager().createQuery(jpaQl);
        return query.getResultList();
    }
    
    public List<Catalogo> obtenerCatalogoPorPadre(Catalogo catPadre, boolean catEstado) throws Exception{
        String jpaQl = "SELECT c FROM Catalogo c"
                + " WHERE c.parentCatCodigo = :parentCatCodigo AND c.catEstado = :catEstado";
        Query query = getEntityManager().createQuery(jpaQl);
        query.setParameter("parentCatCodigo", catPadre);
        query.setParameter("catEstado", catEstado);
        return query.getResultList();
    }
}
